package cc.vv.btpartyjob.partymanager.adapter

import android.text.TextUtils
import android.view.View
import android.widget.TextView
import cc.vv.baselibrary.adapter.SimpleCommonAdapter
import cc.vv.baselibrary.adapter.holder.ExtendViewHolder
import cc.vv.baselibrary.view.LKCircleImageView
import cc.vv.baselibrary.view.OvalImageView
import cc.vv.btpartyjob.jnimodule.server.OperationServer
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.PromisePingJiaObj
import cc.vv.lkimagecomponent2.LKImage
import cc.vv.lkimagecomponent2.lib.mode.ScaleMode
import org.json.JSONObject

/**
 * 党员承诺评价adapter
 * Created by Chen.qi on 2018/10/24.
 */
class PartyPromisePingJiaListAdapter(layoutResId: Int) : SimpleCommonAdapter<PromisePingJiaObj>(layoutResId) {
    override fun convert(helper: ExtendViewHolder, item: PromisePingJiaObj, position: Int) {
        val viewPic = helper.getView<LKCircleImageView>(R.id.lkv_ippL_head)
        if (TextUtils.isEmpty(item.faceUrl)) {
            viewPic?.visibility = View.GONE
        } else {
            viewPic?.visibility = View.VISIBLE
            LKImage.load().load(item.faceUrl).placeHolder(R.mipmap.icon_party_head_def).error(R.mipmap.icon_party_head_def)
                    .scale(ScaleMode.CENTER_CROP).into(viewPic)
        }
        //titile
        helper.getView<TextView>(R.id.tv_ippL_pinJiaName)?.text = item.commentName

        //时间
        helper.getView<TextView>(R.id.tv_ippL_time)?.text = OperationServer.formatStr(item.commentTime)

        try {
            val json = JSONObject(item.content)
            helper.getView<TextView>(R.id.tv_ippL_content)?.text = json.getString("content")
        } catch (e: Exception) {
        }

    }
}